﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using Net.Chirash.Twitter.TwitterClient;

namespace Net.Chirash.Twitter.TwitterZone
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private const string ConsumerKey = "8UwTJZJMJjl4uLZduYvA";
        private const string ConsumerSecret = "eCnmRK0mDSXfjm95j947iixyDaUY3OZleSdkWMhLc";
        private const string AccessToken = "141500207-0sEjrUZwRXujtATsDh4gFSAX3qhCVycqJBtDiWuq";
        private const string AccessTokenSecret = "jZZKmbXhJzh933Eg84P7bEIjNBbp3uNM3q52i8CwU";
        private TwitterConnection Connection { get; set; }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Connection = new TwitterConnection()
            {
                ConsumerKey = ConsumerKey,
                ConsumerSecret = ConsumerSecret,
                Token = AccessToken,
                TokenSecret = AccessTokenSecret,
            };

            TwitterCommand command = new TwitterCommand(Connection);
            int count = 50;
            List<User> list = new List<User>(count);
            ConnectionProgressBar.Visibility = System.Windows.Visibility.Visible;
            TimeLineOption option = new TimeLineOption()
            {
                Count = count
            };
            TimeLine tl = command.GetHomeTimeLine(option);
            foreach (var status in tl.Statuses)
            {
                //list.Add(status.User);
            }
            TimeLineDataGrid.ItemsSource = tl.Statuses;
            ConnectionProgressBar.Visibility = System.Windows.Visibility.Collapsed;
            Title = "Tweet Zone - TimeLine Loaded:" + DateTime.Now.ToShortTimeString();
        }

        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (UpdateTextBox.Text.Length > 0)
            {
                TwitterCommand command = new TwitterCommand(Connection);
                try
                {
                    command.Update(UpdateTextBox.Text);
                    UpdateTextBox.Text = "";
                }
                catch (Exception ex)
                {
                }
            }
        }
    }
}